//
// Created by 11510 on 2024/6/11.
//

#ifndef DEMO_POINT_H
#define DEMO_POINT_H
#include <string>
/**
 * 利用运算符重载，使Point对象能够进行+、+=、前置++、后置++操作（对坐标进行计算）
 */
class Point
{
public:
    Point():_ix(0), _iy(0){}
    Point(int x, int y):_ix(x), _iy(y){}

    friend Point operator+(const Point& lhs, const Point& rhs);

    Point& operator+=(const Point& rhs){
        this->_ix += rhs._ix;
        this->_iy += rhs._iy;

        return *this;
    }

    /**
     * 后置++
     * @return
     */
    Point& operator++(){
        this->_ix++;
        this->_iy++;
        return *this;
    }

    /**
     * 前置++应该返回拷贝构造
     * @return
     */
    Point operator++(int){
        Point backup(this->_ix,this->_iy);
        this->_ix++;
        this->_iy++;

        return backup;
    }

    std::string toString(){
        return "x = " + std::to_string(this->_ix )
        + ", y = " + std::to_string(this->_iy);
    }

private:
    int _ix;
    int _iy;
};

/**
 * 不能返回引用，应该返回默认拷贝构造
 * @param rhs
 * @return
 */
Point operator+(const Point& lhs, const Point& rhs) {
    return Point(lhs._ix + rhs._ix, lhs._iy + rhs._iy);
}

#endif //DEMO_POINT_H
